<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<base href="<%=basePath%>">
<%@include file="/esayuiStyle.jsp" %>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="css/fileImage.css" />

</head>
<script type="text/javascript">
	$(function(){
		//值班医生表格
		$("#doctorTable").datagrid({
			pagination:true,
			idField:"id",
			onSelect:function(rowIndex, rowData){
    			if(rowData.registrationChargeType!=null){
        			$("#doctor_rank_class_type").combobox("setValue",rowData.registrationChargeType.id);		        				
    			}
    			if(rowData.section!=null){
        			$("#registrationSection").combobox("setValue",rowData.section.id);		        					        				
    			}
    			if(rowData.user!=null){
        			$("#registrationDoctor").combobox("setValue",rowData.user.id);		
    			}
    			if(rowData.paymentMethod!=null){
        			$("#registrationPaymentMethod").combobox("setValue",rowData.paymentMethod.id);			        				
    			}
    			if(rowData){
    				
    			}
			}
		});
		//今日挂号表格
		$("#registrationTable").datagrid({
			pagination:true,
			idField:"id",
			toolbar:'#tb',
			//当选中一行时发生:
			onSelect:function(rowIndex, rowData){
				$("#regPatientForm").form("load",rowData.patient);
				$("#preview").attr("src",rowData.patient.image);
				$("#regMessageForm").form("load",rowData);
				$("#registrationId").val(rowData.id);
				$("#registrationPatientId").val(rowData.patient.id);
    			if(rowData.registrationChargeType!=null){
        			$("#doctor_rank_class_type").combobox("setValue",rowData.registrationChargeType.id);		        				
    			}
    			if(rowData.section!=null){
        			$("#registrationSection").combobox("setValue",rowData.section.id);		        					        				
    			}
    			if(rowData.user!=null){
        			$("#registrationDoctor").combobox("setValue",rowData.user.id);		
    			}
    			if(rowData.paymentMethod!=null){
        			$("#registrationPaymentMethod").combobox("setValue",rowData.paymentMethod.id);			        				
    			}
			}
		});
		//查询病人表单
		 $('#patientSelect').combogrid({
			 keyHandler:{
		            up: function() {},
		            down: function() {},
		            enter: function() {},
		            query: function(q) {
		                //动态搜索
		               $('#patientSelect').combogrid("grid").datagrid("reload", {'name': q});
		               $('#patientSelect').combogrid("setValue", q);
		            }
		        },onChange:function(){
		        	var g = $('#patientSelect').combogrid('grid');	// get datagrid object
		        	var r = g.datagrid('getSelected');	// get the selected row
		        	$("#preview").attr("src",r.image);
		        	$("#regPatientForm").form("load",r);
		        	
		        	if(r.gender==1){
			        	$("#userGender").textbox("setValue","男");		        		
		        	}else{
			        	$("#userGender").textbox("setValue","女");		        				        		
		        	}
		        	
		        	//查询该病人今天是否已经挂过号
		        	$("#regMessageForm").form("clear");
		        	//给挂号表单的病人ID隐藏域赋值
		        	$("#registrationPatientId").val(r.id);
		        	var postData = {'patient.id':r.id};
		        	$.post("registration/selectByYseNo",postData,function(data){
		        		if(!jQuery.isEmptyObject(data)){
		        			$("#regMessageForm").form("load",data);
		        			
		        			if(data.registrationChargeType!=null){
			        			$("#doctor_rank_class_type").combobox("setValue",data.registrationChargeType.id);		        				
		        			}
		        			if(data.section!=null){
			        			$("#registrationSection").combobox("setValue",data.section.id);		        					        				
		        			}
		        			if(data.user!=null){
			        			$("#registrationDoctor").combobox("setValue",data.user.id);		
		        			}
		        			if(data.paymentMethod!=null){
			        			$("#registrationPaymentMethod").combobox("setValue",data.paymentMethod.id);			        				
		        			}
		        		}
		        		
		        	})
		        	
				 }
		 })
		//挂号表单李的科室变动时
		$("#registrationSection").combobox({
			onSelect:function(record){
				if($("#doctor_rank_class_type").val()>0){
					$("#registrationDoctor").combobox("clear");
					$("#registrationDoctor").combobox("reload","user/selectShiftDoctor?registrationChargeTypeId="+$("#doctor_rank_class_type").val()+"&sectionId="+record.id+"");	
				}else{
					$.messager.alert("提示","请选择类型","warning");
				}
			}
		})
		//挂号表单李的挂号类型变动时
		$("#doctor_rank_class_type").combobox({
			onSelect:function(record){
				if($("#registrationSection").val()>0){
					$("#registrationDoctor").combobox("clear");
					$("#registrationDoctor").combobox("reload","user/selectShiftDoctor?registrationChargeTypeId="+record.id+"&sectionId="+$("#registrationSection").val()+"");			
				}
				$.post("registrationChargeType/selectById",{id:record.id},function(data){
					$("#registrationMoney").val(data.money);
					$("#registrationMoney").textbox('setValue',data.money);
	
					
				})
			}
		})
	})
	function registerStateFormatter(value,row,index){
		if(row.registerState==0){
			return "未登记";
		}else{
			return "已登记";
		}
	}
	//挂号
	function registration(){
		if($("#patientId").val()==""){
			$.messager.alert("提示","请选择病人","warning");
			return "";
		}else if($("#registrationDoctor").val()==""){
			$.messager.alert("提示","请填写完整挂号信息!","warning");
		}else{
			$("#regMessageForm").form("submit",{
				url:"registration/registration",
				success:function(data){
					var result = (eval('(' + data + ')')).result;
					$.messager.alert("提示",result,"warning");
					$("#doctorTable").datagrid("reload");
					$("#registrationTable").datagrid("reload");
					$("#regPatientForm").form("clear");
					$("#regMessageForm").form("clear");
					$("#preview").attr("src",'');
				}
			})
		}
	}
	
	//换号
	function changeSigns(){
		if($("#patientId").val()==""){
			$.messager.alert("提示","请选择病人","warning");
			return "";
		}else if($("#registrationDoctor").val()==""){
			$.messager.alert("提示","请填写完整挂号信息!","warning");
		}else{
			var postData = {'patient.id':$("#registrationPatientId").val()};
			$.post("registration/selectByYseNo",postData,function(data){
				console.log(data);
				if(jQuery.isEmptyObject(data)){
					$.messager.alert("提示","该病人还没有挂号或已登记，无法换号，请选择挂号！","warning");					
				}else{
				console.log("查到了");					
					$("#regMessageForm").form("submit",{
						url:"registration/changeSigns",
						success:function(data){
							var result = (eval('(' + data + ')')).result;
							$.messager.alert("提示",result,"warning");
							$("#doctorTable").datagrid("reload");
							$("#registrationTable").datagrid("reload");
							$("#regPatientForm").form("clear");
							$("#regMessageForm").form("clear");
							$("#preview").attr("src",'');
						}
					})
				}
			})
		}
	}
	//退号
	function hmsRepulse(){
		if($("#patientId").val()==""){
			$.messager.alert("提示","请选择病人","warning");
			return "";
		}else if($("#registrationDoctor").val()==""){
			$.messager.alert("提示","请填写完整挂号信息!","warning");
		}else{
			if($("#registrationId").val()==''){
				$.messager.alert("提示","该病人还未登记挂号,无法退号！","warning");				
			}else{
				$.messager.confirm("提示","确定要退号吗？",function(r){
					if(r){
						$.post("registration/hmsRepulse",{id:$("#registrationId").val()},function(data){
							console.log(data.result);
							$.messager.alert("提示",data.result,"warning");							
						})
						
					}
				})
			}
		}
	}
	//清空
	function empty (){
		$("#regPatientForm").form("clear");
		$("#regMessageForm").form("clear");
		$("#preview").attr("src",'');
	}
	
	function keshiFormatter(value,row,index){
		return row.section.name;
	}

	function patientGenderFormatter(value,row,index){
		var a = "";
		if(value==1){
			a="男"
		}else{
			a="女"
		}
		return a;
	}
	function userFormatter(value,row,index){
		if(row.user!=null){
			return row.user.name;
		}
	};
	//添加病人档案
	function addPatient(){
		addDialog("添加病人档案",500,800,"patient/patientfrom","#patientForm","patient/patientAdd","#patientTable");
	}
	
</script>
    <script type="text/javascript" src="js/registration.js"></script>
	<script type="text/javascript" src="js/DoctorRankClassJs.js"></script>
	<script type="text/javascript" src="js/registrationSelect.js"></script>
<body class="">
<div id="p" class="easyui-panel"  style="width:100%;height:50px;padding:5px;">
	<div data-options="region:'north'" style="height:13%;padding: 0px 10px">
			<select id="patientSelect" class="easyui-combogrid" style="width:250px" data-options="
					prompt:'输入关键字后自动搜索',
        			mode:'remote',  
					panelWidth: 700,
					idField: 'id',
					textField: 'name',
					url: 'patient/patientList',
					method: 'get',
					editable:true,  
					dataType:'json',
					pagination: true,
					columns: [[
						{field:'id',title:'Id',width:80},
						{field:'identification',title:'标识',width:120},
						{field:'name',title:'名称',width:80,align:'right'},
						{field:'gender',title:'性别',width:80,align:'right',formatter:patientGenderFormatter},
						{field:'idCard',title:'身份证',width:200},
						{field:'phone',title:'手机号',width:60,align:'center'},
						{field:'money',title:'余额',width:60,align:'center'}
					]],
					keyHandler:{
						
					},
				fitcolumns: true, 
				label: '姓名/身份证:', 
				labelposition: 'left', 
				fitColumns: true
				">
			</select>
			<a href="javaScript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-back'">搜索病人</a>
			<a href="javaScript:void(0)" class="easyui-linkbutton" onclick="addPatient()" data-options="plain:true,iconCls:'icon-back'">建档</a>
			<a href="javaScript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-back'" onclick="registration()">挂号</a>
			<a href="javaScript:void(0)" class="easyui-linkbutton" onclick="changeSigns()" data-options="plain:true,iconCls:'icon-back'">换号</a>
			<a href="javaScript:void(0)" class="easyui-linkbutton" onclick="hmsRepulse()" data-options="plain:true,iconCls:'icon-back'">退号</a>
			<a href="javaScript:void(0)" class="easyui-linkbutton" onclick="empty()" data-options="plain:true,iconCls:'icon-back'">清空</a>
	</div>
</div>
<div id="patient" class="easyui-panel" title="病人信息" style="width:100%;padding:10px;">
	<form id="regPatientForm" method="post" >
		<input type="hidden" id="patientId" name="id" />
		<div style="float: left; margin-right: 20px;">
	           <a href="javaScript:void(0)" class="a-upload">
	                   <img id="preview" src="" width="100px" height="100px" alt="">
	           </a>
		</div>
		<div>
			<div style="display: inline-block;margin-right: 10px;margin-top:15px; margin-bottom: 15px;">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">标识:</label>
				<input class="easyui-textbox" id="patientIdentification" name="identification" style="width:150px" data-options="readonly:true">						
			</div>
			<div style="display: inline-block;margin-right: 10px;margin-bottom: 15px;">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">姓名:</label>
				<input class="easyui-textbox" id="patientName" name="name" style="width:150px" data-options="readonly:true">						
			</div>
			<div style="display: inline-block;margin-right: 10px;margin-bottom: 15px;">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">性别:</label>
				<input class="easyui-textbox" id="patientGender" name="gender" style="width:150px" data-options="readonly:true,formatter:patientGenderFormatter">						
			</div>
			<div style="display: inline-block;margin-right: 10px;margin-bottom: 15px;">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">身份证:</label>
				<input class="easyui-textbox" id="patientIdCard" name="idCard" style="width:150px" data-options="readonly:true">						
			</div>
			<br />
			<div style="display: inline-block;margin-right: 10px;margin-bottom: 15px;">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">年龄:</label>
				<input class="easyui-textbox" id="patientAge" name="age" style="width:150px" data-options="readonly:true">						
			</div>
			<div style="display: inline-block;margin-right: 10px;margin-bottom: 15px;">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">联系电话:</label>
				<input class="easyui-textbox" id="patientPhone" name="phone" style="width:150px" data-options="readonly:true">						
			</div>
			<div style="display: inline-block;margin-right: 10px;margin-bottom: 15px;">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">出生日期:</label>
				<input class="easyui-textbox" id="patientBirthday" name="birthday" style="width:150px" data-options="readonly:true">						
			</div>
		</div>
	</form>
</div>
<div id="registration" class="easyui-panel" title="挂号信息" style="width:100%;padding:10px;">
	<form id="regMessageForm" method="post" >
		<input type="hidden" id="registrationPatientId" name="patient.id" />
		<input type="hidden" id="registrationId" name="id" />
		<div style="display: inline-block;margin-right: 10px;margin-top:15px; margin-bottom: 15px;">
			<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">挂号类型:</label>
		    <input id="doctor_rank_class_type" class="easyui-combobox" name="registrationChargeType.id" style="width:150px;" data-options=" 
			      url:'registrationChargeType/selectAll', 
			      method:'get', 
			      valueField:'id', 
			      textField:'typeName', 
			      panelheight:'auto',
			      required:true
	      	">						
		</div>
		<div style="display: inline-block;margin-right: 10px;margin-top:15px; margin-bottom: 15px;">
			<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">科室:</label>
		    <input id="registrationSection" class="easyui-combobox" name="section.id" style="width:150px;" data-options=" 
			      url:'section/selectAll', 
			      method:'get', 
			      valueField:'id', 
			      textField:'name', 
			      panelheight:'auto',
			      required:true
	      	">						
		</div>

		<div style="display: inline-block;margin-right: 10px;margin-top:15px; margin-bottom: 15px;">
			<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">医生:</label>
		    <input id="registrationDoctor" class="easyui-combobox" name="user.id" style="width:150px;" data-options=" 
			      url:'', 
			      method:'get', 
			      valueField:'id', 
			      textField:'name', 
			      panelheight:'auto',
			      required:true
	      	">						
		</div>
		<div style="display: inline-block;margin-right: 10px;margin-top:15px; margin-bottom: 15px;">
			<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">类型:</label>
		    <input id="registrationType" class="easyui-combobox" name="type" style="width:150px;" data-options=" 
			      url:'', 
			      method:'get', 
			      valueField:'id', 
			      textField:'value', 
			      panelheight:'auto',
			      data: [{
						id: '1',
						value: '初诊'
					},{
						id: '2',
						value: '复诊'
					}],
			      required:true
	      	">						
		</div>
		<div style="display: inline-block;margin-right: 10px;margin-top:15px; margin-bottom: 15px;">
			<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">支付方式:</label>
		    <input id="registrationPaymentMethod" class="easyui-combobox" name="paymentMethod.id" style="width:150px;" data-options=" 
			      url:'dictionary/selectValueByKey', 
			      method:'get', 
			      valueField:'id', 
			      textField:'value', 
			      panelheight:'auto',
			      queryParams: { key: 'payment_ method' },
			      required:true
	      	">						
		</div>
		<div style="display: inline-block;margin-right: 10px;margin-top:15px; margin-bottom: 15px;">
			<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">挂号费用:</label>
			<input class="easyui-textbox" id="registrationMoney" name="registrationMoney" style="width:150px" data-options="readonly:true">			
		</div>
	</form>
</div>
<div class="easyui-tabs tabs-block tab-color-black" data-options="plain:true" style="height:100%">
  <div title="今日排版" style="padding:0px">
	<table class="easyui-datagrid" id="doctorTable" 
			data-options="url:'doctorRankClass/list',method:'post',fitColumns:true,striped:true,rownumbers:true,singleSelect:true ">
		<thead>
			<tr>
				<th data-options="field:'type'" width="100">类型</th>
				<th data-options="field:'section',align:'right',formatter:keshiFormatter"  width="100">科室id</th>
				<th data-options="field:'user',align:'right',formatter:userFormatter" width="100">医生</th>
				<th data-options="field:'amLimitNumber',align:'right'" width="100">上午限号</th>
				<th data-options="field:'amRegistrationNumber',align:'right'" width="100">上午挂号</th>
				<th data-options="field:'pmLimitNumber',align:'right'" width="100">下午限号</th>
				<th data-options="field:'pmRegistrationNumber',align:'right'" width="100">下午挂号</th>
			</tr>
		</thead>
	</table>
  </div>
  <div title="今日挂号" data-options="iconCls:'icon-help'" id="todayRegistration" style="padding:0px">
		<div id="tb">
			
			 	<input class="easyui-textbox" id="patientName" name="patient.name" label="Name:" labelposition="left" style="width:250px;">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">挂号类型:</label>
			    <input id="todayRegistrationRankClassType" class="easyui-combobox" name="" style="width:150px;" data-options=" 
				      url:'registrationChargeType/selectAll', 
				      method:'get', 
				      valueField:'id', 
				      textField:'typeName', 
				      panelheight:'auto'
		      	">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">类型:</label>
			    <input id="todayRegistrationType" class="easyui-combobox" name="" style="width:150px;" data-options=" 
				      url:'', 
				      method:'get', 
				      valueField:'id', 
				      textField:'value', 
				      panelheight:'auto',
				      data: [{
							id: '1',
							value: '初诊'
						},{
							id: '2',
							value: '复诊'
						}]
		      	">
				<label class="textbox-label textbox-label-left" for="_easyui_textbox_input2" style="text-align: left;width:60px; height: 26px; line-height: 26px;">科室:</label>
			    <input id="todayRegistrationSection" class="easyui-combobox" name="" style="width:150px;" data-options=" 
				      url:'section/selectAll', 
				      method:'get', 
				      valueField:'id', 
				      textField:'name', 
				      panelheight:'auto'
		      	">
		      	
		    	<a id="btn" href="javaScript:void(0)" onclick="registrationSelectCondition()" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">serch</a>

		</div>
		<table class="easyui-datagrid" id="registrationTable" 
				data-options="url:'registration/selectByToday',method:'post',fitColumns:true,striped:true,rownumbers:true,singleSelect:true ">
			<thead>
				<tr>
					<th data-options="field:'patient',formatter:patientFormatter" width="100">病人</th>
					<th data-options="field:'registrationChargeType',align:'right',formatter:registrationChargeTypeFormatter" width="100">挂号类型</th>
					<th data-options="field:'type',align:'right',formatter:registrationTypeFormatter" width="100">类型</th>
					<th data-options="field:'section',align:'right',formatter:sectionFormatter"  width="100">科室id</th>
					<th data-options="field:'user',align:'right',formatter:userFormatter" width="100">医生</th>
					<th data-options="field:'stage',align:'right',formatter:stageFormatter" width="100">上午/下午</th>
					<th data-options="field:'registrationMoney',align:'right'" width="100">金额</th>
					<th data-options="field:'registerState',align:'right',formatter:registerStateFormatter" width="100">登记状态</th>
				</tr>
			</thead>
		</table>
  </div>
</div>
</body>


</html>